package logic

import (
	"context"
	"errors"
	"houseRpc/models"

	"houseRpc/house"
	"houseRpc/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type CreateOrderLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewCreateOrderLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateOrderLogic {
	return &CreateOrderLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *CreateOrderLogic) CreateOrder(in *house.CreateOrderRequest) (*house.CreateOrderResponse, error) {
	// todo: add your logic here and delete this line

	var err error
	var b models.Booking

	b.HouseId = int(in.HouseId)
	b.UserId = int(in.UserId)
	b.BkDate = in.BkDate

	if err = b.CreateOrder(); err != nil {
		logx.Error("预约订单创建失败")
		return nil, errors.New("预约订单创建失败")
	}
	return &house.CreateOrderResponse{
		HouseId: in.HouseId,
		UserId:  in.UserId,
	}, nil
}
